.TH C++SIM 3A "23 September 1994" "C++SIM" "C++SIM Reference Manual"
.SH NAME
Process \- main simulation entity
.SH SYNOPSIS
.B "#ifndef PROCESS_H_"
.br
.B "#   include <ClassLib/Process.h>"
.br
.B "#endif"
.sp
.BI "class Process : public Thread"
.br
.BI "{"
.br
.BI "public:"
.br
.BI "	static const int Never;"
.sp
.BI "	virtual ~Process ();"
.sp
.BI "	static double CurrentTime ();"
.br
.BI "	double Time () const;"
.sp
.BI "	double evtime () const;"
.sp
.BI "	const Process* next_ev () const;"
.sp
.BI "	void Activate ();"
.br
.BI "	void ActivateBefore (Process &);"
.br
.BI "	void ActivateAfter (Process &);
.br
.BI "	void ActivateAt (double AtTime = CurrentTime(),"
.br
.BI "				Boolean prior = FALSE);"
.br
.BI "	void ActivateDelay (double AtTime = CurrentTime(),"
.br
.BI "				    Boolean prior = FALSE);"
.sp
.BI "	void ReActivate ();"
.br
.BI "	void ReActivateBefore (Process &);"
.br
.BI "	void ReActivateAfter (Process &);"
.br
.BI "	void ReActivateAt (double AtTime = CurrentTime(),"
.br
.BI "					Boolean prior = FALSE);"
.br
.BI "	void ReActivateDelay (double AtTime = CurrentTime(),"
.br
.BI "					Boolean prior = FALSE);"
.sp
.BI "	void Cancel ();"
.br
.BI "	Boolean idle () const;"
.sp
.BI "	Boolean passivated () const;"
.br
.BI "	Boolean terminated () const;"
.br
.BI "	virtual void terminate ();"
.sp
.BI "	static const Process* current ();"
.sp
.BI "	virtual void Body () = 0;"
.sp
.BI "	virtual void reset ();"
.sp
.BI "protected:"
.br
.BI "	Process ();"
.br
.BI "	Process (int priority);"
.br
.BI "	Process (int priority, unsigned long stackSize);"
.sp
.BI "	void Hold (double t);"
.br
.BI "	void Passivate ();"
.br
.BI "};"
.SH DESCRIPTION
This is the main class in the C++SIM system, representing the simulation
entities themselves. It provides operations for the direct control of
these processes by other (user) classes and also by the simulation
.B
scheduler
object.

Processes run according to a logical simulation time: only
one process is ever truly active at any instance of real time,
but many processes may be active at the same simulation time.

A
.B
Process
will be in one of four possible states:
.sp
.I
	Active
: the process is currently running, and its actions are being
executed.
.sp
.I
	Suspended
: the process is on the scheduler queue, scheduled to become
active at a specific time in the future. This may be the same
simulation time as the currently active process.
.sp
.I
	Passive
: the process is not on the scheduler queue, and unless another
process brings it back onto the list by means of one of the
activation statements, its further actions will not be executed.
.sp
.I
	Terminated
: the process is not on the scheduler queue and has no further
actions to execute. Once a process is terminated it cannot be
activated again.

It is not possible to create instances of this class by virtue
of the fact that its constructor is
.I
protected
because a
.B
Process
itself represents an abstract entity - the real entity must be
provided by the deriving classes.

The default constructor creates a process with the default
Thread(3A) priority and stack allocation. The other two
constructors allow for the modification of both of these
parameters.

The
.I
static
constant
.B
Never
represents a special simulation time: processes with this time will
never be reactivated by the
.B
scheduler.

The methods
.B
CurrentTime
and
.B
Time
both return the current simulation time. The former is a
.I
static
method and can therefore be invoked without an instance
of the class which the latter version requires.

.B
evtime
returns the simulation time at which the process is scheduled
to be activate.

.B
next_ev
returns the next process (relative to this process) on the
scheduler queue. If the current process is not on the scheduler
queue then this returns a
.B
NULL
pointer.

There are five
.B
Activate
methods which operate only on passive processes:

     1) at the current simulation time
     2) before another process, 
     3) after another process, 
     4) at a specified (simulated) time, or 
     5) after a specified (simulated) delay


The five corresponding
.B
ReActivate
methods apply to both active processes and
those on the scheduler queue.

If the process is on the scheduler queue, then
.B
Cancel
removes it and makes it passive. Otherwise it does nothing.

.B
idle
returns
.B
TRUE
if the process is passive or terminated, otherwise
.B
FALSE
is returned (i.e., it is either active or present on
the scheduler queue).

.B
passivated
indicates whether the process is passive.

.B
terminated
indicates whether the process has been terminated.

.B
terminate
removes the process from the scheduler queue if necessary
and sets the process status to terminated. Once this is
done the process can never be reactivated.

.B
current
returns the currently active process.

.B
Body
represents the actual code for the process which is
executed when the process is active. This is a
.I
pure virtual
function, and must be defined in one of the deriving
classes before an instance can be declared.

.B
reset
is used for resetting the process prior to another simulation
run. To reset a simulation, the
.B
reset
method of the
.B
scheduler
must be called, and this resets all of
the processes currently on the simulation queue.

When invoked by the active process
.B
Hold
reschedules the currently active process for activation
at a later time indicated by the supplied parameter.

.B
Passivate
removes the currently active process from the scheduler
queue. It will not be rescheduled unless another process
invokes one of the activation methods.

.SH SEE ALSO
reset(3A), Scheduler(3A), Thread(3A)
